<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../libs/vue.js"></script>
</head>
<body>
    <div id="app">
        <h1>{{myTime | getTime('~')}}</h1>
    </div>
    <div id="app1">
        <h1>{{myTime | getTime('/')}}</h1>
    </div>
    <script>
        let vm = new Vue({
            el:'#app',
            data:{
                myTime:Date.now()
            },
            // 私有过滤器
            filters:{
                getTime(val,type){
                    let date = new Date(val)
                    let year = date.getFullYear()
                    let month = date.getMonth() + 1
                    let day = date.getDate()
                    let h = date.getHours()
                    let m = date.getMinutes()
                    let s = date.getSeconds()
                    return year + type + month + type + day + ' ' + h + ':' + m + ':' + s
                }
            }
        })
        let vm1 = new Vue({
            el:'#app1',
            data:{
                myTime:Date.now()
            },
            // 私有过滤器
            filters:{
                getTime(val,type){
                    let date = new Date(val)
                    let year = date.getFullYear()
                    let month = date.getMonth() + 1
                    let day = date.getDate()
                    let h = date.getHours()
                    let m = date.getMinutes()
                    let s = date.getSeconds()
                    return year + type + month + type + day + ' ' + h + ':' + m + ':' + s
                }
            }
        })
    </script>
</body>
</html>